package com.rui.iterator.model;

import java.util.List;

/**
 * @Description: 迭代器接口实现类
 * @Author: ZhangRui
 * @Date: 2023/3/3 16:44
 * @Version: 1.0
 */
public class IteratorImpl<T> implements Iterator<T> {

    private List<T> list;
    private int cursor;
    private T element;

    public IteratorImpl(List<T> list) {
        this.list = list;
    }

    @Override
    public Boolean hasNext() {
        return cursor < list.size();
    }

    @Override
    public T next() {
        element = list.get(cursor);
        cursor++;
        return element;
    }
}
